package com.example.yyjc.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.yyjc.config.EncryptorConfig;
import com.example.yyjc.domain.industryanalyze.DeliveryCountry;
import com.example.yyjc.domain.industryanalyze.SecondCatSale;
import com.example.yyjc.service.CountryService;
import com.example.yyjc.service.IndustryAnalyzeService;
import com.example.yyjc.service.SelectionService;
import com.example.yyjc.util.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * @ClassName IndustryAnalyzeController
 * @Description TODO    行业分析
 * @Author lvyongwei
 * @Date 2020-11-19 15:24
 **/
@RestController
@CrossOrigin
@RequestMapping("/industry")
public class IndustryAnalyzeController {

    @Autowired
    private IndustryAnalyzeService industryAnalyzeService;

    @Autowired
    private SelectionService selectionService;

    @Autowired
    private CountryService countryService;

    @Autowired
    private CountryController countryController;

    /**
     * 获取所有一级类目
     * @return
     */
    @PostMapping("/getFirstTitle")
    public ResultBean getFirstTitle(){
        return ResultBean.success(industryAnalyzeService.getFirstCatTitle());
    }

    /**
     * 根据一级目录获取其下所有二级目录及销量
     * @param data
     * @return
     */
    @PostMapping("/getSecondCatTitle")
    public ResultBean getSecondCatTitle(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer firstCatTitleId = jsonObject.getInteger("firstCatTitleId");
        return ResultBean.success(industryAnalyzeService.getSecondCatTitle(firstCatTitleId));
    }

    /**
     * 根据二级目录id获取其占一级目录比例
     * @param data
     * @return
     */
    @PostMapping("/getSecondCatScale")
    public ResultBean getSecondCatScale(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        return ResultBean.success(industryAnalyzeService.getScale(secondCatTitleId));
    }

    /**
     * 获取某个二级类目销量和销售额情况
     * @param data
     * @return
     */
    @PostMapping("/getSecondCatSale")
    public ResultBean getSecondCatSale(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        /**
         * 获取时间
         */
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        /**
         * 格式化日期
         */
        List<String> timess = new ArrayList<>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取每个月份销量
         */
        List<SecondCatSale> secondCatSales = industryAnalyzeService.getSecondCatSalesVolume(secondCatTitleId,times);
        /**
         * 获取每个月销量(单位十万)
         */
        List<String> secondCatSales2 = new ArrayList<String>();
        for(int i = 0;i < secondCatSales.size(); i++){
            secondCatSales2.add(String.format("%.2f",(double)secondCatSales.get(i).getSecondCatSaleVolume() /100000));
        }
        /**
         * 获取销售额
         */
        List<String> values = new ArrayList<String>();
        for(int i = 0;i < secondCatSales.size(); i++){
            values.add(String.format("%.2f",(double)secondCatSales.get(i).getSecondCatSaleVolume() * secondCatSales.get(i).getSecondCatPrice()/1000000));
        }
        /**
         * 返回表格数据(后加)
         */
        List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
        for(int i=0;i<timess.size();i++){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("time",timess.get(i));
            jsonObject1.put("secondCatSales",secondCatSales2.get(i));
            jsonObject1.put("saleroom",values.get(i));
            jsonObjects.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = new ResultBean();
        resultBean.put("keys",timess);
        resultBean.put("secondCatSales",secondCatSales2);
        resultBean.put("values",values);
        resultBean.put("table",jsonObjects);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * 获取某个二级类目增幅
     * @param data
     * @return
     */
    @PostMapping("/getSecondCatIncrease")
    public ResultBean getSecondCatIncrease(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        /**
         * 获取时间
         */
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        List<String> time2 = countryService.getAllTimeAsc2();
        int begin = time2.indexOf(beginTime);
        int end = time2.indexOf(endTime);
        /**
         * 格式化日期
         */
        List<String> timess = new ArrayList<>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取每个月份销量
         */
        List<SecondCatSale> secondCatSales = industryAnalyzeService.getSecondCatSalesVolume(secondCatTitleId,time2);
        /**
         * 获取销售额=销量*价格 环比增幅
         */
        List<String> values = new ArrayList<String>();
        for(int i = 0;i < secondCatSales.size(); i++){
            if(i != 0){
                SecondCatSale secondCatSale = secondCatSales.get(i);
                SecondCatSale secondCatSale1 = secondCatSales.get(i-1);
                values.add(String.format("%.2f", (double) (secondCatSale.getSecondCatSaleVolume()*secondCatSale.getSecondCatPrice() - secondCatSale1.getSecondCatSaleVolume()*secondCatSale1.getSecondCatPrice()) / (double) (secondCatSale1.getSecondCatSaleVolume()*secondCatSale1.getSecondCatPrice())*100));
            }else{
                values.add("0");
            }
        }
        //判断是区间内
        if(!StringUtils.isEmpty(beginTime) && !StringUtils.isEmpty(endTime)){
            values = values.subList(begin,end+1);
        }
        /**
         * 返回table
         */
        ArrayList<JSONObject> jsonObjects = new ArrayList<>();
        for(int i=0;i<timess.size();i++){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("time",timess.get(i));
            jsonObject1.put("value",values.get(i));
            jsonObjects.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = new ResultBean();
        resultBean.put("keys",timess);
        resultBean.put("values",values);
        resultBean.put("table",jsonObjects);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * 获取二级类目各个月份的价格
     * @param data
     * @return
     */
    @PostMapping("/getSecondCatPrice")
    public ResultBean getSecondCatPrice(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        /**
         * 获取时间
         */
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        List<String> time2 = countryService.getAllTimeAsc2();
        int begin = time2.indexOf(beginTime);
        int end = time2.indexOf(endTime);
        /**
         * 格式化日期
         */
        List<String> timess = new ArrayList<>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取每个月份销量
         */
        List<SecondCatSale> secondCatSales = industryAnalyzeService.getSecondCatSalesVolume(secondCatTitleId,time2);
        /**
         * 价格 环比增幅
         */
        List<String> values = new ArrayList<String>();
        for(int i = 0;i < secondCatSales.size(); i++){
            if(i != 0){
                SecondCatSale secondCatSale = secondCatSales.get(i);
                SecondCatSale secondCatSale1 = secondCatSales.get(i-1);
                values.add(String.format("%.2f", (double) (secondCatSale.getSecondCatPrice() - secondCatSale1.getSecondCatPrice()) / (double) (secondCatSale1.getSecondCatPrice())*100));
            }else{
                values.add("0");
            }
        }
        //判断是区间内
        if(!StringUtils.isEmpty(beginTime) && !StringUtils.isEmpty(endTime)){
            values = values.subList(begin,end+1);
            secondCatSales = secondCatSales.subList(begin,end+1);
        }
        /**
         * 返回表格数据(后加)
         */
        List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
        for(int i=0;i<timess.size();i++){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("time",timess.get(i));
            jsonObject1.put("secondCatSales",secondCatSales.get(i).getSecondCatPrice());
            jsonObject1.put("saleroom",values.get(i));
            jsonObjects.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = new ResultBean();
        resultBean.put("keys",timess);
        resultBean.put("secondCatSales",secondCatSales);
        resultBean.put("values",values);
        resultBean.put("table",jsonObjects);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * 获取某个二级目录国家市场级别分析
     * @param data
     * @return
     */
    @PostMapping("/getCountryRanking")
    public ResultBean getCountryRanking(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String time = jsonObject.getString("time");
        List<SecondCatSale> secondCatSales = industryAnalyzeService.getCountryRanking(secondCatTitleId,time);
        /**
         * 求和
         */
        double sum = industryAnalyzeService.getCountrySum(secondCatTitleId,time);
        /**
         * 计算占比
         */
        List<String> list = new ArrayList<String>();
        for(int i=0;i<secondCatSales.size();i++){
            if(i==0){
                list.add(String.format("%.2f",secondCatSales.get(i).getSecondCatSaleVolume()/sum*100));
            }else{
                list.add(String.format("%.2f",(((secondCatSales.get(i).getSecondCatSaleVolume())/sum*100)*100 + (Double.valueOf(list.get(i-1)))*100)/100));
            }
        }
        for(int i=0;i<list.size();i++){
            secondCatSales.get(i).setScale(Double.valueOf(list.get(i)));
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = new ResultBean();
        resultBean.put("secondCatSales",secondCatSales);
        //resultBean.put("list",list);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * 获取发货地分布   7-1
     * @param data
     * @return
     */
    @PostMapping("/getDeliveryCount")
    public ResultBean getDeliveryCount(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        List<String> timess = new ArrayList<String>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 前三国家
         */
        List<String> countries = industryAnalyzeService.getDeliveryCountry(secondCatTitleId);
        List<JSONObject> values = new ArrayList<JSONObject>();
        for(String country:countries){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",country);
            jsonObject1.put("data",industryAnalyzeService.getDeliveryCountryCount(country,times,secondCatTitleId));
            values.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(countries,values,timess);
        resultBean.put("times",timess);
        resultBean.put("countries",countries);
        resultBean.put("values",values);
        resultBean.put("code",200);
        return resultBean;
    }

    /**
     * 获取行业某个月份卖家发货信息
     * @param data
     * @return
     */
    @PostMapping("/getAllDeliveryCountryCount")
    public ResultBean getAllDeliveryCountryCount(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String time = jsonObject.getString("time");
        try{
            List<DeliveryCountry> deliveryCountries = industryAnalyzeService.getAllDeliveryCountryCount(secondCatTitleId,time);
            /**
             * 读取properties文件
             */
            InputStream in = IndustryAnalyzeController.class.getResourceAsStream("/CountryTranslate.properties");
            //读取文件
            Properties properties=new Properties();
            properties.load(new InputStreamReader(in, "GBK"));
            for(DeliveryCountry deliveryCountry:deliveryCountries){
                String countryName = properties.getProperty(deliveryCountry.getCountryName().replaceAll(" ",""));
                if(countryName == null){
                    deliveryCountry.setCountryName("未知");
                }
                deliveryCountry.setCountryName(countryName);
            }
            return ResultBean.success("获取信息成功",deliveryCountries);
        }catch (Exception e){
            e.printStackTrace();
            return ResultBean.error("获取信息失败");
        }
    }

    /**
     * 获取二级类目各个月份价格区间商品数量比例
     * @param data
     * @return
     */
    @PostMapping("/getPriceSectionGoodsCountScale")
    public ResultBean getPriceSectionGoodsCountScale(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        List<String> timess = new ArrayList<String>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取二级类目各个月份价格区间内商品数量
         */
        List<String> priceSections = industryAnalyzeService.getPriceSection();
        /**
         * 获取二级类目各个月份价格区间内商品数量比例
         */
        List<JSONObject> values = new ArrayList<JSONObject>();
        for(String priceSection:priceSections){
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("name",priceSection);
            jsonObject2.put("data",industryAnalyzeService.getGoodsCountScale(times,secondCatTitleId,priceSection));
            values.add(jsonObject2);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(priceSections,values,timess);
        resultBean.put("times",timess);
        resultBean.put("priceSections",priceSections);
        resultBean.put("values",values);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * 获取二级类目各个月份价格区间商品数量
     * @param data
     * @return
     */
    @PostMapping("/getPriceSectionGoodsCount")
    public ResultBean getPriceSectionGoodsCount(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        List<String> timess = new ArrayList<String>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取二级类目各个月份价格区间内商品数量
         */
        List<String> priceSections = industryAnalyzeService.getPriceSection();
        List<JSONObject> values = new ArrayList<JSONObject>();
        for(String priceSection:priceSections){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",priceSection);
            jsonObject1.put("data",industryAnalyzeService.getGoodsCount(times,secondCatTitleId,priceSection));
            values.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(priceSections,values,timess);
        resultBean.put("times",timess);
        resultBean.put("priceSections",priceSections);
        resultBean.put("values",values);
        resultBean.put("code",200);
        return resultBean;
    }

    /**
     * 获取二级类目各个月份订单区间商品数量占比
     * @param data
     * @return
     */
    @PostMapping("/getOrderSectionGoodsCountScale")
    public ResultBean getOrderSectionGoodsCountScale(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        List<String> timess = new ArrayList<String>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取二级类目各个月份订单区间内商品数量
         */
        List<String> orderSections = industryAnalyzeService.getOrderSection();
        /**
         * 获取二级类目各个月份订单区间内商品数量比例
         */
        List<JSONObject> values = new ArrayList<JSONObject>();
        for(String orderSection:orderSections){
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("name",orderSection);
            jsonObject2.put("data",industryAnalyzeService.getOrderCountScale(times,secondCatTitleId,orderSection));
            values.add(jsonObject2);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(orderSections,values,timess);
        resultBean.put("times",timess);
        resultBean.put("orderSections",orderSections);
        resultBean.put("values",values);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * 获取二级类目各个月份订单区间商品数量
     * @param data
     * @return
     */
    @PostMapping("/getOrderSectionGoodsCount")
    public ResultBean getOrderSectionGoodsCount(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        List<String> timess = new ArrayList<String>();
        for(String time:times){
            StringBuilder sb = new StringBuilder(time);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取二级类目各个月份订单区间内商品数量
         */
        List<String> orderSections = industryAnalyzeService.getOrderSection();
        List<JSONObject> values = new ArrayList<JSONObject>();
        for(String orderSection:orderSections){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",orderSection);
            jsonObject1.put("data",industryAnalyzeService.getOrderCount(times,secondCatTitleId,orderSection));
            values.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(orderSections,values,timess);
        resultBean.put("times",timess);
        resultBean.put("orderSections",orderSections);
        resultBean.put("values",values);
        resultBean.put("code",200);
        return resultBean;
    }

    /**
     * 获取二级类目行业下top10店铺信息
     * @param data
     * @return
     */
    @PostMapping("/getSecondCatShopTopTen")
    public ResultBean getSecondCatShopTopTen(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String time = jsonObject.getString("time");
        return ResultBean.success(industryAnalyzeService.getSecondCatShopTopTen(secondCatTitleId,time));
    }


    /**
     * 获取二级类目行业下top10商品信息
     * @param data
     * @return
     */
    @PostMapping("/getSecondCatGoodsTopTen")
    public ResultBean getSecondCatGoodsTopTen(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String time = jsonObject.getString("time");
        return ResultBean.success(industryAnalyzeService.getSecondCatGoodsTopTen(secondCatTitleId,time));
    }


    /**
     * 获取行业的TOP10国家的各国家TOP3物流渠道
     * @param data
     * @return
     */
    @PostMapping("/getTopTenCountryLogistics")
    public ResultBean getTopTenCountryLogistics(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String time = jsonObject.getString("time");
        return ResultBean.success(industryAnalyzeService.getTopTenCountryLogistics(secondCatTitleId,time));
    }


    /**
     * 获取top1物流前三国家订单数量
     * @param data
     * @return
     */
    @PostMapping("/getTopOneLogisticsTopThree")
    public ResultBean getTopOneLogisticsTopThree(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        Integer secondCatTitleId = jsonObject.getInteger("secondCatTitleId");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        //获取时间
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        //格式化时间
        List<String> timess = new ArrayList<String>();
        for(String time1:times){
            StringBuilder sb = new StringBuilder(time1);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        //排名前三的国家
        List<String> countryNames = industryAnalyzeService.getTopOneLogisticsTopThree(secondCatTitleId,beginTime,endTime);
        //返回数据
        List<JSONObject> jsonObjectList = new ArrayList<JSONObject>();
        for(String countryName:countryNames){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",countryName);
            jsonObject1.put("data",industryAnalyzeService.getCountryTopOneLogisticsCount(secondCatTitleId,times,countryName));
            //添加数据
            jsonObjectList.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(countryNames,jsonObjectList,timess);
        resultBean.put("times",timess);
        resultBean.put("countryNames",countryNames);
        resultBean.put("values",jsonObjectList);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * Aliexpress物流物流-标准前三国家情况
     * @param data
     * @return
     */
    @PostMapping("/getAliexpressCondition")
    public ResultBean getAliexpressCondition(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        String time = jsonObject.getString("time");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        //获取时间
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        //格式化时间
        List<String> timess = new ArrayList<String>();
        for(String time1:times){
            StringBuilder sb = new StringBuilder(time1);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取Aliexpress物流前三国家
         */
        List<String> stringList = industryAnalyzeService.getAliexpressTopCountry();
        //存储返回数据
        List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
        for(String string:stringList){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",string);
            jsonObject1.put("data",industryAnalyzeService.getAliexpressTopCountryScale(times,string,stringList));
            jsonObjects.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(stringList,jsonObjects,timess);
        resultBean.put("times",timess);
        resultBean.put("countryNames",stringList);
        resultBean.put("values",jsonObjects);
        resultBean.put("code",200);
        return resultBean;
    }


    /**
     * Aliexpress物流物流-标准前三类目情况
     * @param data
     * @return
     */
    @PostMapping("/getAliexpressCatCondition")
    public ResultBean getAliexpressCatCondition(@RequestBody String data){
        /**
         * 解析参数
         */
        JSONObject jsonObject = JSONObject.parseObject(data);
        String time = jsonObject.getString("time");
        String beginTime = jsonObject.getString("beginTime");
        String endTime = jsonObject.getString("endTime");
        //获取时间
        List<String> times = selectionService.getAllTimeAsc(beginTime,endTime);
        //格式化时间
        List<String> timess = new ArrayList<String>();
        for(String time1:times){
            StringBuilder sb = new StringBuilder(time1);
            sb.insert(4,"年");
            sb.append("月");
            timess.add(sb.toString());
        }
        /**
         * 获取Aliexpress物流前三类目
         */
        List<String> stringList = industryAnalyzeService.getAliexpressTopSecondCat();
        //存储返回数据
        List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
        for(String string:stringList){
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",string);
            jsonObject1.put("data",industryAnalyzeService.getAliexpressTopSecondCatScale(times,string,stringList));
            jsonObjects.add(jsonObject1);
        }
        /**
         * 设置返回对象
         */
        ResultBean resultBean = countryController.getTable(stringList,jsonObjects,timess);
        resultBean.put("times",timess);
        resultBean.put("secondCatNames",stringList);
        resultBean.put("values",jsonObjects);
        resultBean.put("code",200);
        return resultBean;
    }
}